package com.base.core

import android.os.Bundle
import androidx.lifecycle.Observer
import com.lib.base.base.BaseActivity
import com.lib.base.base.BaseView
import com.lib.base.data.http.HttpCode

abstract class BaseModuleActivity : BaseActivity() {

    var baseViewModelIml: BaseViewModelIml? = null

    override val reload: Boolean
        get() = false

    override var statusBarColor: Int? = null

    override fun initData(savedInstanceState: Bundle?) {
        baseViewModelIml = BaseViewModelIml(BaseModuleRepository())
    }

    override fun initView() {
        baseViewModelIml?.httpNetCode?.observe(this, Observer {
            when (it) {
                HttpCode.UNAUTHORIZED -> {
                    changeBaseView(BaseView.STATE.NET_ERROR)
                }
                HttpCode.NETWORK_ERROR -> {
                    changeBaseView(BaseView.STATE.NET_ERROR)
                }
                HttpCode.NOT_FOUND -> {
                    changeBaseView(BaseView.STATE.NOT_FOUND)
                }
                HttpCode.HTTP_ERROR -> {
                    changeBaseView(BaseView.STATE.NET_ERROR)
                }
                HttpCode.RESULT_NULL -> {
                    changeBaseView(BaseView.STATE.RESULT_NULL)
                }
                HttpCode.SUCCESS -> changeBaseView(BaseView.STATE.OK)
                HttpCode.LOADING -> changeBaseView(BaseView.STATE.LOADING)
                else -> {
                    changeBaseView(BaseView.STATE.NET_ERROR)
                }
            }
        })
    }
}